<?php

namespace IDock\Insurance\ACIC\Response;

use IDock\Http\Response;

class UploadResultQueryResponse extends AllACICResponse
{
    protected $info = [];

    protected $status = '';

    public function resolve(): Response
    {
        $body = $this->getBody();

        if ($body) {
            libxml_disable_entity_loader(false);
            $body = simplexml_load_string($body);

            $body = $this->objectToArray($body);

            $errorCode = $body['Head']['ErrorCode'] ?? '';

            if ($errorCode !== '0000') {
                if ($error = $this->errorTrans($body['Head']['ErrorMessage'] ?? '未知错误')) {
                    $this->setError($error);
                } else {
                    $this->setError($body['Head']['ErrorMessage'] ?? '未知错误');

                }
                return  $this;
            }
            $this->setBody($body['Body'] ?? '');
            $this->info = $this->get('Info',[]);
            $this->status = $this->info['Status'] ?? '';
        }

        return $this;
    }

    /**
     * @return string
     */
    public function getStatus(): string
    {
        return $this->status;
    }
}